package com.app.bimo.commonbusiness.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PatternUtil {
	public static boolean isEmail(String email) {
		String str = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
		Pattern p = Pattern.compile(str);
		Matcher m = p.matcher(email);

		return m.matches();
	}


	public static  boolean isMobileNO(String mobiles) {
		Pattern p = Pattern
				.compile("^((13[0-9])|(15[^4,\\D])|(18[0-9]))\\d{8}$");
		Matcher m = p.matcher(mobiles);
		return m.matches();
	}

	/**
	 * 去掉首尾换行
	 * @param str
	 * @return
	 */
	public static String replaceBlank(String str) {
		if(str==null){
			return "";
		}
        String dest =str. trim().replaceAll("(^\\s+|\\s+$)", "");
//        if (str!=null) {
//            Pattern p = Pattern.compile("\\s*|\t|\r|\n");
//            Matcher m = p.matcher(str);
//            dest = m.replaceAll("");
//        }
        return dest;
    }

	/**
	 * 去掉所有的
	 * @param str
	 * @return
	 */
	public static String replace(String str) {
        String dest ="";
        if (str!=null) {
            Pattern p = Pattern.compile("\\s*|\t|\r|\n");
            Matcher m = p.matcher(str);
            dest = m.replaceAll("");
        }
        return dest;
    }
	
	public static boolean isMobileNO(String rule,String phone){
		Pattern p = Pattern.compile(rule);
		Matcher m = p.matcher(phone.trim()
				.replaceAll("\\s*", ""));
		if (!m.matches()) {
			return false;
		}
		return true;
	}
}
